/**
 * Title: FileTransferTask.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-9-24 下午3:28:45
 * Version 1.0
 */
package com.luoxudong.phonenumber.service.net.http.filetransfer.manager;

import android.content.Context;

import com.luoxudong.phonenumber.service.net.http.asynchttp.AsyncHttpRequest;
import com.luoxudong.phonenumber.service.net.http.asynchttp.RequestParams;
import com.luoxudong.phonenumber.service.net.http.filetransfer.vo.RequestHolder;
import com.luoxudong.phonenumber.service.net.http.filetransfer.vo.TransferType;
import com.luoxudong.phonenumber.service.pool.constant.ThreadPoolConst;

/** 
 * ClassName: FileTransferTask
 * Description:文件传输任务
 * Create by 罗旭东
 * Date 2013-9-24 下午3:28:45
 */
public class FileTransferTask{
	private static final long serialVersionUID = 1L;

	private Context context = null;
	
	/**
	 * 传输类型
	 */
	private int transferType = 0;
	
	/**
	 * 文件传输ID
	 */
	private int transferId = 0;
	
	/**
	 * 传输状态
	 */
	private int transferStatus = 0;
	
	/**
	 * 请求参数
	 */
	private RequestHolder requestHolder = null;

	/**
	 * 文件传输http请求
	 */
	private AsyncHttpRequest httpRequest = null;
	
	/**
	 * 开始上传或下载
	 */
	public void start()
	{
		httpRequest = new AsyncHttpRequest();
		httpRequest.setThreadPoolType(ThreadPoolConst.THREAD_TYPE_FILE_HTTP);
		
		RequestParams params = null;
		if (transferType == TransferType.download.getValue())//下载
		{
			params = requestHolder.getDownloadParams();
			httpRequest.get(context, requestHolder.getUrl(), params);
		}
		else if (transferType == TransferType.upload.getValue())//上传
		{
			params = requestHolder.getUploadParams();
			httpRequest.post(requestHolder.getUrl(), params, params.getResponseHandler());
		}
		
		
	}
	
	/**
	 * 取消上传或下载任务
	 */
	public void cancel()
	{
		if (httpRequest != null)
		{
			httpRequest.cancel();
		}
	}
	
	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public int getTransferType() {
		return transferType;
	}

	public void setTransferType(int transferType) {
		this.transferType = transferType;
	}

	public int getTransferId() {
		return transferId;
	}

	public void setTransferId(int transferId) {
		this.transferId = transferId;
	}

	public int getTransferStatus() {
		return transferStatus;
	}

	public void setTransferStatus(int transferStatus) {
		this.transferStatus = transferStatus;
	}

	public RequestHolder getRequestHolder() {
		return requestHolder;
	}

	public void setRequestHolder(RequestHolder requestHolder) {
		this.requestHolder = requestHolder;
	}
	
}
